﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using MovieDB.DTOs;
using MovieDB.RepositoryInterfaces;
using MovieDB.ServiceInterfaces;
using MovieDB.Services;
using MovieDB.Test.Common;

namespace MovieDB.Test
{
    [TestClass]
    public class SearchServiceTest : BaseTest<MovieService>
    {
        private Mock<ILogger> _loggerMock;
        private Mock<IMovieRepository> _searchRepositoryMock;


        [TestInitialize]
        public override void Init()
        {
            //init mocks
            _searchRepositoryMock = new Mock<IMovieRepository>();
            _loggerMock = new Mock<ILogger>();

            //register all needed components
            RegisterMock(_searchRepositoryMock.Object);
            RegisterMock(_loggerMock.Object);

            //must be called, to get the proper behavior
            base.Init();
        }

        [TestMethod, ExpectedException(typeof (ArgumentNullException))]
        public void SaveMovie_ReceivesNull_ThrowsArgumentNullException()
        {
            //arrange
            //note nothing to do here


            //act
            ServiceToTest.SaveMovie(null);


            //assert
            //note nothing to do here
        }

        [TestMethod]
        public void SaveMovie_ReceivesAMovie_SaveOnRepositoryShouldBeCalled()
        {
            //arrange
            var movieDto = new MovieDto();

            _searchRepositoryMock.Setup(sr => sr.SaveMovie(movieDto));

            //act
            ServiceToTest.SaveMovie(movieDto);

            //assert
            _searchRepositoryMock.Verify(sr => sr.SaveMovie(movieDto), Times.Once());
        }
    }
}